package cn.edu.nju.software.cdiy.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import cn.edu.nju.software.cdiy.bean.Brand;
import cn.edu.nju.software.cdiy.bean.Hardware;
import cn.edu.nju.software.cdiy.bean.HardwareSet;
import cn.edu.nju.software.cdiy.bean.Power;
import cn.edu.nju.software.cdiy.bean.Scheme;
import cn.edu.nju.software.cdiy.dao.PowerDao;
import cn.edu.nju.software.cdiy.dao.SchemeDao;
import cn.edu.nju.software.cdiy.service.Service;
import cn.edu.nju.software.cdiy.service.UtilService;
import cn.edu.nju.software.cdiy.util.BusinessConstant;
import cn.edu.nju.software.cdiy.util.Item;
import cn.edu.nju.software.cdiy.util.SortType;
import cn.edu.nju.software.cdiy.util.SortWay;

public class PowerServiceImpl implements Service<Power> {
	
	@Autowired
	private PowerDao powerDao;
	@Autowired
	private SchemeDao schemeDao;
	@Autowired
	private UtilService utilService;

	public void setPowerDao(PowerDao powerDao) {
		this.powerDao = powerDao;
	}

	public void setSchemeDao(SchemeDao schemeDao) {
		this.schemeDao = schemeDao;
	}

	public void setUtilService(UtilService utilService) {
		this.utilService = utilService;
	}

	public List<Power> getPowerList(int p, SortType s, HardwareSet hs, SortWay sw) {
		return powerDao.getPowerList(p, s, utilService.fillHardwareSet(hs), sw);
	}

	@Override
	public List<Hardware> getNewestList() {
		return powerDao.getNewestList();
	}

	@Override
	public List<Hardware> getHottestList() {
		return powerDao.getHottestList();
	}

	@Override
	public List<Brand> getBrandList() {
		return powerDao.getBrandList();
	}
	

	@Override
	public List<Power> filter(int page,Map<String, List<Integer>> map,SortType st,SortWay sw,HardwareSet hs) {
		return powerDao.filter(page, map, st, sw, utilService.fillHardwareSet(hs));
	}
	
	@Override
	public List<Power> search(String keywords,int page) {
		return powerDao.search(keywords, page);
	}

	@Override
	public Map<String,List<Item>> getFilterBoard() {
		return powerDao.getFilterBoard();
	}

	@Override
	public Power getOneById(int id) {
		return powerDao.getOneById(id);
	}

	@Override
	public Map<String, List<String>> getInsertboard() {
		return powerDao.getInsertboard();
	}
	
	@Override
	public boolean insertHardware(Map<String, List<String>> map) {
		return powerDao.insertHardware(map);
	}

	@Override
	public void save(Power t) {
		powerDao.save(t);
	}

	@Override
	public int getFilterResultLength(Map<String, List<Integer>> map,HardwareSet hs) {
		return powerDao.filterPageNum(map, utilService.fillHardwareSet(hs));
	}

	@Override
	public List<Scheme> getRelatedSchemes(int hardwareId) {
		return schemeDao.getFourScheme(hardwareId, BusinessConstant.H_POWER);
	}
	
	@Override
	public List<Power> getSupplierHarewares(int id) {
		// TODO Auto-generated method stub
		return powerDao.getOneBySupplierID(id);
	}
}
